﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Test_CheckBox
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
            checkbox.Text = "显示密码";
            textbox.Text = "123456";
            textbox.Dock = DockStyle.Right;
            checkbox.Checked = false; //勾选状态
            checkbox.Dock = DockStyle.Top; // 设置 CheckBox 控件停靠在窗体的顶部
          // 设置 CheckBox 控件的四个角与窗体的四个角对齐
          //checkbox.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right| AnchorStyles.Bottom;
             this.Controls.Add(checkbox);
            this.Controls.Add(textbox);
        }

        //勾选事件
        private void checkbox_CheckedChanged(object sender, EventArgs e)
        {
            Console.WriteLine("勾选成功");
            bool isChecked = checkbox.Checked;
            if (isChecked == true)
            {
                textbox.PasswordChar = '\0';
            }
            else
            {
                textbox.PasswordChar = '*';
            }
        }

        CheckBox checkbox = new CheckBox();
        TextBox textbox = new TextBox();

    }
}
